package member.order.service;

import m.common.model.util.ModelUpdate;
import m.common.model.util.QueryCondition;
import m.common.service.Service;
import m.system.exception.MException;
import member.order.model.RechargeOffset;
import member.order.model.StoreSettle;

public class StoreSettleService extends Service {
    public void updateAmount(StoreSettle settle) throws MException {
        ModelUpdate.init(StoreSettle.class)
            .set("payAmount", RechargeOffset.class,
                "ifnull(sum(if(#{order.inputStore.oid}='"+settle.getInputStore().getOid()+"',#{payAmount},-#{payAmount})),0)",
                QueryCondition.eq("settle.oid",settle.getOid()))
            .set("giveAmount", RechargeOffset.class,
                "ifnull(sum(if(#{order.inputStore.oid}='"+settle.getInputStore().getOid()+"',#{giveAmount},-#{giveAmount})),0)",
                QueryCondition.eq("settle.oid",settle.getOid()))
            .setExp("settleAmount","#{payAmount}+#{giveAmount}")
            .execute(settle.getOid());
    }
}
